// https://codeforces.com/contest/1658/submission/156887237
#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int &v : a) cin >> v;
  if (count(a.begin(), a.end(), 1) != 1) {
    cout << "NO\n";
    return;
  }
  int p = find(a.begin(), a.end(), 1) - a.begin();
  rotate(a.begin(), a.begin() + p, a.end());
  for (int i = 1; i < n; ++i)
    if (a[i] - a[i - 1] > 1) {
      cout << "NO\n";
      return;
    }
  cout << "YES\n";
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int tc;
  cin >> tc;
  while (tc--) solve();
  return 0;
}
